<?php
require_once('oxy/src/Engine/Types/ID.php');
require_once('oxy/src/Oxygen.php');
require_once('oxy/src/Engine/Scope.php');
	
	
function __autoload($class) {
	$f = Oxygen::FindClassFile($class);
	if (is_null($f)) return;
	require_once($f);
}
	

//ob_start('output_filter');
//function output_filter($buffer) {
//	if (preg_match('/(Fatal error<\/b>:)(.+) in <b>(.+)<\/b> on line <b>(.+)<\/b>(<br)/i', $buffer, $matches) ) {
//		user_exception_handler(new ErrorException($matches[2], 0, E_ERROR, $matches[3], $matches[4]));
//  }
//  return $buffer;
//}
//register_shutdown_function('flush_output');
//function flush_output(){
//	while ( ob_get_level() > 0 ) ob_end_flush();
//}
    
    
set_error_handler("user_error_handler");
function user_error_handler($severity, $msg, $filename, $linenum, $content) {
	throw new ErrorException($msg, 0, $severity, $filename, $linenum);
}

set_exception_handler("user_exception_handler");
function user_exception_handler($ex) {
	while ( ob_get_level() > 0 ) ob_end_clean();
//	echo '<html><body>';
	echo '<div style="position:fixed;top:0;bottom:0;left:0;right:0;z-index:999;background:#555577;">';
	echo '<div style="position:fixed;top:30px;bottom:30px;left:30px;right:30px;z-index:1000;background:#dddddd;">';
	echo '<div style="position:fixed;top:39px;bottom:39px;left:39px;right:39px;z-index:1000;border:1px solid #bbbbbb;background:#fafafa;overflow:auto;padding:30px;">';
	
	echo '<div style="font:bold 18px/22px Trebuchet MS,sans-serif;border-bottom:1px solid #bbbbbb;color:#555555;">Fatal error</div>';
	echo '<div style="font:bold 13px/14px Trebuchet MS,sans-serif;margin:20px 0;">'.$ex->getMessage().'</div>';
	echo '<div style="font:11px/13px Trebuchet MS,sans-serif;border-left:1px solid #bbbbbb;margin-left:3px;padding:10px;white-space:pre;color:#999999;"><![CDATA['.$ex->getTraceAsString().']]></div>';
	echo '<div style="font:11px/13px Trebuchet MS,sans-serif;border-left:1px solid #bbbbbb;margin-left:3px;margin-top:20px;padding:10px;white-space:pre;color:#999999;"><![CDATA['.Database::GetQueriesAsString().']]></div>';
	echo '<div style="font:italic 11px/13px Trebuchet MS,sans-serif;color:#bbbbbb;margin-top:50px;">Oxygen</div>';
	
	echo '</div>';
	echo '</div>';
	echo '</div>';
	//	echo '</body></html>';
}



?>